//
//  ViewController.m
//  19-JSON
//
//  Created by 李昊林 on 16/8/9.
//  Copyright © 2016年 李昊林. All rights reserved.
//

#import "ViewController.h"
#import "LHLLayout.h"
#import "ContentTitle.h"

@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,LHLLayoutDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *myCollectionView;
@property (nonatomic, strong)NSMutableArray<ContentTitle *>*contentTitleArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _contentTitleArray = [NSMutableArray array];
    // Do any additional setup after loading the view, typically from a nib.
    
//    [self delegate]
    
    
    
    LHLLayout *layout = (LHLLayout *)self.myCollectionView.collectionViewLayout;
    layout.delegate = self;
}

- (void)handleDate {
    //数组初始化
    // JSON解析
    // 通过一个data, 将JSON转换层OC认识的内容
    // 数组/字典
    NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"FirstJSON" ofType:@"json"];
    NSData *jsonData = [NSData dataWithContentsOfFile:dataPath];
    //NSJSONReadingOption
    NSError *error = nil;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
   // NSArray *list = jsonDic[@"tabs"][@"list"];
    for (NSDictionary *contenDic in list){
        
    }
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout heightForItemAtIndexPath:(NSIndexPath *)indexPath{

    ContentTitle *contentTitle = _contentTitleArray[indexPath.row];
    CGRect newRect = [ContentTitle.title boundingrre]
    CGFloat width = ceilf(CGRectGetWidth(newRect));
    return CGSizeMake(100, 40);
    
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout widthForItemAtIndexPath:(NSIndexPath *)indexPath height:(CGFloat)height {
    return 100;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _contentTitleArray.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UICollectionViewCell" forIndexPath:indexPath];
    return cell;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
